package com.zmm.huoqiumaishou.ui.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.youth.banner.Banner;
import com.zmm.huoqiumaishou.Constant;
import com.zmm.huoqiumaishou.R;
import com.zmm.huoqiumaishou.bean.BuyType;
import com.zmm.huoqiumaishou.bean.Other;
import com.zmm.huoqiumaishou.bean.Shuffling;
import com.zmm.huoqiumaishou.ui.view.IFoundView;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class FoundFragment extends Fragment implements IFoundView, SwipeRefreshLayout.OnRefreshListener {

    private SwipeRefreshLayout mSwipeRefreshWidget;
    private Banner banner;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_found, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        //下拉刷新控件
        mSwipeRefreshWidget = (SwipeRefreshLayout) view.findViewById(R.id.swrfl_found_fragment);
        mSwipeRefreshWidget.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_green_light, android.R.color.holo_red_light, android.R.color.holo_orange_light);
        mSwipeRefreshWidget.setOnRefreshListener(this);//设置下拉刷新监听

        //recycleView
        RecyclerView mRecyclerView = (RecyclerView) view.findViewById(R.id.recycle_found_fragment);
        StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(manager);

        //添加适配器
//        mRecyclerView.setAdapter();


    }


    @Override
    public String[] getPath() {
        return Constant.FOUND_PATH;
    }
    //轮播数据加载成功
    @Override
    public void addShufflings(List<Shuffling> list) {
        List<String> imgPaths = new ArrayList<>();
        List<String> titles = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            imgPaths.add(list.get(i).getImg());
            titles.add(list.get(i).getTitle());
        }

//        //设置banner样式
//        banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE);
//        //设置图片加载器
//        banner.setImageLoader(new GlideImageLoader());
//        //设置图片集合
//        banner.setImages(imgPaths);
//        //设置banner动画效果
//        banner.setBannerAnimation(Transformer.DepthPage);
//        //设置标题集合（当banner样式有显示title时）
//        banner.setBannerTitles(titles);
//        //设置自动轮播，默认为true
//        banner.isAutoPlay(true);
//        //设置轮播时间
//        banner.setDelayTime(1500);
//        //设置指示器位置（当banner模式中有指示器时）
//        banner.setIndicatorGravity(BannerConfig.CENTER);
//        //banner设置方法全部调用完毕时最后调用
//        banner.start();
    }
    //买手类型数据加载成功
    @Override
    public void addBuyTypes(List<BuyType> list) {

    }
    //其他数据加载成功
    @Override
    public void addOthers(List<Other> list) {

    }


    //加载失败
    @Override
    public void showLoadFailMsg() {
        Toast.makeText(getActivity(), "网络异常！", Toast.LENGTH_SHORT).show();
    }
    //显示进度
    @Override
    public void showLoadingView() {
        mSwipeRefreshWidget.setRefreshing(true);
    }
    //取消进度
    @Override
    public void hideLoadingView() {
        mSwipeRefreshWidget.setRefreshing(false);
    }
    //加载网络数据
    @Override
    public void onRefresh() {

    }
}
